import { FIRST_ORDER_RETURN_ORDER_OPTIONS, PURCHASEWAY_OPTIONS, QC_STATGE_OPTIONS } from '@/constant/purchase'
import { Checkbox, Empty, Form, FormInstance } from 'antd'
import dayjs from 'dayjs'
import React from 'react'

export const useFormBase = ({
  detailInfo,
  WareHouseOptions,
  handleSearchWareHouse,
  UserOptions,
  handleSearchUser,
  DICTDATA,
  isRoot,
}: {
  detailInfo: Record<string, any>
  WareHouseOptions: IOptionItem[]
  handleSearchWareHouse: (newValue: string) => void
  UserOptions: IOptionItem[]
  handleSearchUser: (newValue: string) => void
  DICTDATA: IDICTDATAType
  isRoot: boolean
}): IItemArray[] => {
  return [
    {
      label: '采购方式',
      type: 'Custom',
      slot: detailInfo?.purchaseType === 1 ? '现采' : detailInfo?.purchaseType === 0 ? '集采' : '-',
    },
    {
      label: '商品季节',
      type: 'Custom',
      slot: detailInfo?.productSeason || '-',
    },
    {
      label: '季节分组',
      type: 'Custom',
      slot: detailInfo?.seasonGroup || '-',
    },
    {
      label: '年份',
      type: 'Custom',
      slot: detailInfo?.year || '-',
    },
    {
      label: '大类',
      type: 'Custom',
      slot: detailInfo?.firstClassName || '-',
    },
    {
      label: '供应商',
      type: 'Custom',
      slot: detailInfo?.supplierName || '-',
    },
    {
      name: 'warehouse',
      label: '仓库',
      type: 'Select',
      option: WareHouseOptions,
      placeholder: '请选择仓库',
      config: {
        suffixIcon: null,
        showSearch: true,
        optionFilterProp: 'label',
        filterOption: false,
        onSearch: handleSearchWareHouse,
        notFoundContent: <Empty description="请输入内容搜索" image={Empty.PRESENTED_IMAGE_SIMPLE} />,
      },
      rules: [{ required: true, message: '请选择仓库' }],
    },
    {
      label: '',
      type: 'Custom',
      slot: (
        <Form.Item name="freeze" label="入库时是否冻结" labelCol={{ span: 14 }} valuePropName="checked">
          <Checkbox></Checkbox>
        </Form.Item>
      ),
    },
    {
      name: 'batchNum',
      label: '批次',
      type: 'InputNumber',
      placeholder: '请输入批次',
      config: {
        precision: 0,
        min: 0,
      },
      // rules: [
      //   {
      //     required: true,
      //     message: '请输入批次',
      //   },
      // ],
    },
    {
      name: 'requiredArrivalTime',
      label: '要求到货日期',
      type: 'DatePicker',
      placeholder: '请选择要求到货日期',
      rules: [
        {
          required: true,
          message: '请选择要求到货日期',
        },
      ],
    },
    {
      name: 'trackOffice',
      label: '跟单办事处',
      type: 'Input',
      placeholder: '请输入跟单办事处',
      config: {
        showCount: true,
        maxLength: 30,
      },
    },
    {
      name: 'trackOrderPersonWorkId',
      label: '供应链跟单',
      type: 'Select',
      option: UserOptions,
      placeholder: '请选择供应链跟单',
      config: {
        suffixIcon: null,
        showSearch: true,
        optionFilterProp: 'label',
        filterOption: false,
        labelInValue: true,
        onSearch: handleSearchUser,
        notFoundContent: <Empty description="请输入内容搜索" image={Empty.PRESENTED_IMAGE_SIMPLE} />,
        fieldNames: { label: 'label', value: 'workId' },
      },
      rules: [{ required: true, message: '请选择供应链跟单' }],
    },
    {
      name: 'replyDeliveryTime',
      label: '供应链回复发货日期',
      type: 'DatePicker',
      placeholder: '请选择供应链回复发货日期',
      hidden: !isRoot,
    },
    {
      name: 'seasonCode',
      label: '订单季节',
      type: 'Select',
      option: DICTDATA.order_season,
      placeholder: '请选择订单季节',
      rules: [
        {
          required: true,
          message: '请选择订单季节',
        },
      ],
      config: {
        optionFilterProp: 'label',
      },
    },
  ]
}

export const useFormAdd = ({
  WareHouseOptions,
  handleSearchWareHouse,
  UserOptions,
  handleSearchUser,
  DICTDATA,
  classBig,
  SupplierOption,
  handleSearchSupplier,
  setfirstClassConfigName,
}: {
  WareHouseOptions: IOptionItem[]
  handleSearchWareHouse: (newValue: string) => void
  UserOptions: IOptionItem[]
  handleSearchUser: (newValue: string) => void
  DICTDATA: IDICTDATAType
  classBig: IOptionItem[]
  SupplierOption: IOptionItem[]
  handleSearchSupplier: (newValue: string) => void
  setfirstClassConfigName: React.Dispatch<React.SetStateAction<string>>
}): IItemArray[] => {
  return [
    {
      label: '首单/返单',
      name: 'orderType',
      type: 'Select',
      option: FIRST_ORDER_RETURN_ORDER_OPTIONS,
      rules: [
        {
          required: true,
          message: '请选择首单/返单',
        },
      ],
    },
    {
      label: '采购方式',
      name: 'purchaseType',
      type: 'Select',
      option: PURCHASEWAY_OPTIONS,
      rules: [
        {
          required: true,
          message: '请选择采购方式',
        },
      ],
    },
    {
      label: '商品季节',
      name: 'productSeasonCode',
      type: 'Select',
      option: DICTDATA.sales_season,
      rules: [
        {
          required: true,
          message: '请选择商品季节',
        },
      ],
    },
    {
      name: 'seasonGroup',
      label: '季节分组',
      type: 'Select',
      option: DICTDATA.season_classify,
      placeholder: '请选择季节分组',
      config: {
        optionFilterProp: 'label',
      },
    },
    {
      name: 'year',
      label: '年份',
      type: 'DatePicker',
      placeholder: '请选择年份',
      rules: [
        {
          required: true,
          message: '请选择年份',
        },
      ],
      config: {
        picker: 'year',
        format: 'YYYY',
      },
    },
    {
      label: '大类',
      name: 'firstClassConfigId',
      type: 'Select',
      option: classBig,
      rules: [
        {
          required: true,
          message: '请选择年份',
        },
      ],
      config: {
        onChange: (_: any, item: any) => {
          setfirstClassConfigName(item.label)
        },
      },
    },
    {
      name: 'supplierId',
      label: '供应商',
      type: 'Select',
      option: SupplierOption,
      placeholder: '请选择供应商',
      rules: [
        {
          required: true,
          message: '请选择供应商',
        },
      ],
      config: {
        suffixIcon: null,
        showSearch: true,
        optionFilterProp: 'label',
        filterOption: false,
        onSearch: handleSearchSupplier,
      },
    },
    {
      name: 'warehouse',
      label: '仓库',
      type: 'Select',
      option: WareHouseOptions,
      placeholder: '请选择仓库',
      config: {
        suffixIcon: null,
        showSearch: true,
        optionFilterProp: 'label',
        filterOption: false,
        onSearch: handleSearchWareHouse,
        notFoundContent: <Empty description="请输入内容搜索" image={Empty.PRESENTED_IMAGE_SIMPLE} />,
      },
      rules: [{ required: true, message: '请选择仓库' }],
    },
    {
      name: 'planDate',
      label: '企划意向交期',
      type: 'DatePicker',
      placeholder: '请选择企划意向交期',
    },
    {
      name: 'requiredArrivalTime',
      label: '要求到货日期',
      type: 'DatePicker',
      placeholder: '请选择要求到货日期',
      rules: [
        {
          required: true,
          message: '请选择要求到货日期',
        },
      ],
    },
    {
      name: 'trackOrderPersonWorkId',
      label: '供应链跟单',
      type: 'Select',
      option: UserOptions,
      placeholder: '请选择供应链跟单',
      config: {
        suffixIcon: null,
        showSearch: true,
        optionFilterProp: 'label',
        filterOption: false,
        labelInValue: true,
        onSearch: handleSearchUser,
        notFoundContent: <Empty description="请输入内容搜索" image={Empty.PRESENTED_IMAGE_SIMPLE} />,
        fieldNames: { label: 'label', value: 'workId' },
      },
      rules: [{ required: true, message: '请选择供应链跟单' }],
    },
    {
      name: 'seasonCode',
      label: '订单季节',
      type: 'Select',
      option: DICTDATA.order_season,
      placeholder: '请选择订单季节',
      rules: [
        {
          required: true,
          message: '请选择订单季节',
        },
      ],
      config: {
        optionFilterProp: 'label',
      },
    },
  ]
}

export const useFormAudit = ({ formAudit }: { formAudit: FormInstance }): IItemArray[] => {
  const isShow = Form.useWatch('auditStatus', formAudit)
  return [
    {
      name: 'auditStatus',
      label: '审核结果',
      option: [
        { label: '审核通过', value: 1 },
        { label: '不通过', value: 0 },
      ],
      type: 'Radio',
    },
    {
      name: 'remark',
      label: '备注',
      type: 'TextArea',
      placeholder: '请输入备注',
      config: {
        showCount: true,
        maxLength: 100,
      },
      rules: isShow ? null : [{ required: true, message: '请输入备注' }],
      hidden: isShow,
    },
  ]
}
export const useFormQc = (): IItemArray[] => {
  return [
    {
      name: 'qualityPhase',
      label: 'QC阶段',
      option: QC_STATGE_OPTIONS,
      type: 'Select',
      rules: [
        {
          required: true,
          message: '请选择QC阶段',
        },
      ],
    },
    {
      name: 'scheduleQualityTime',
      label: '预约QC时间',
      type: 'DatePicker',
      placeholder: '请选择预约QC时间',
      rules: [
        {
          required: true,
          message: '请选择预约QC时间',
        },
      ],
      config: {
        minDate: dayjs(),
      },
    },
  ]
}
export const useFormsurvey = (): IItemArray[] => {
  return [
    {
      name: 'personQty',
      label: '预计车缝人数',
      type: 'Input',
    },
    {
      name: 'dailyProduceQty',
      label: '预计日产量',
      type: 'Input',
    },
  ]
}
export const useNumberAdd = ({ stylecolorOptions }: { stylecolorOptions: IOptionItem[] }): IItemArray[] => {
  return [
    {
      name: 'stylecolor',
      label: '款色',
      type: 'Select',
      option: stylecolorOptions,
      placeholder: '请选择款色',
      config: {
        showSearch: true,
        filterOption: true,
        optionFilterProp: 'label',
      },
      rules: [
        {
          required: true,
          message: '请选择款色',
        },
      ],
    },
    {
      name: 'reportDate',
      label: '汇报日期',
      type: 'DatePicker',
      placeholder: '请选择汇报日期',
      rules: [
        {
          required: true,
          message: '请选择汇报日期',
        },
      ],
    },
    {
      name: 'totalProductQty',
      label: '累计成品数',
      type: 'InputNumber',
      placeholder: '请输入累计成品数',
      config: {
        precision: 0,
        min: 0,
      },
      rules: [
        {
          required: true,
          message: '请输入累计成品数',
        },
      ],
    },
    {
      name: 'remark',
      label: '备注',
      type: 'TextArea',
      placeholder: '请输入备注',
      config: {
        showCount: true,
        maxLength: 100,
      },
    },
  ]
}
